# ............... # A Python Quiz # ............... # .................................................... # The Task: # Find the answer to life, the universe and everything # .................................................... # define a variable 'first' as the remainder of 49:5 first = 49 % 5 print(first) # define an empty list with the name 'first_list' first_list = [] # fill 'first_list' with all numbers from 1 to 100 in steps of 5 for i in range(1, 100, 5): first_list.append(+ i) print(first_list) # define a variable 'second' as the number of elements in 'first_list' second = len(first_list) print('this is second', second) # define 'second_list' where every element is twice the corresponding element in 'first_list', # but only for elements in 'first_list' that are smaller than 50 second_list = [2 * x for x in first_list if x < 50] print(second_list) # define a variable 'third' as the maximum in 'second_list' third = max(second_list) print(third) # as long as an iterator starting at 'first' is smaller than 'third' # increase a new variable 'fourth' starting at 'third' #fourth = 0 while first < third: fourth = third + 1 first = first + 1 print('this is fourth', fourth) print('this is first', first) # define a function 'diff' that subtracts b from a and returns the result def diff(a, b): """calculate (a - b) * 2""" return (a-b)*2 # define a variable 'fifth' that stores the result of a call of diff with a = 'fourth' and b = 'first' fifth = diff(fourth, first) print('this is fifth', fifth) # finally, define a variable 'answer' as two times 'second' + fifth answer = 2 * second + fifth # create an output that says: The answer to life, the universe and everything is 'answer'. print('') print('-------------------------------------------------------') print('The answer to life, the universe and everything is', answer, '.') print('-------------------------------------------------------')